<?php
/**
 * Created by PhpStorm.
 * User: GZ-1
 * Date: 2017/6/5
 * Time: 9:50
 */

// 账号登录
include_once "../util.php";

$js_account=$_REQUEST['account'];
if(empty($js_account)){
    $c_output=array(
        'stats'=>0,
        'msg'=>'账号或密码错误'
    );
    echo json_encode($c_output);
    return;
}
$js_account = json_decode($js_account);
$account=objectToArray($js_account);

// 通过登录账号获取对应用户的信息，并判断密码是否相等
$result = selectRecordByKey('users', 'uname', $account['uname']);
if($result['upass']!=$account['upass']){
    echo json_encode(array(
        'stats'=>0,
        'msg'=>'账号或密码错误'
    ));
    return;
}

// 获取用户登录的会话密钥ssid  saveSessionKey($usid,$skey,$ssid,$loginWay)
$ssid=uuid();
$s_result = saveSessionKey($result['usid'], "", $ssid, 0);
if($s_result) {
    // 获取用户的数据
    echo json_encode(array(
        'stats'=>1,
        'self'=>$result,
        'ssid'=>$ssid,
        'userRows'=>getAllUsers($result['usid'])
    ));
}else{
    echo json_encode(array(
        'stats'=>0,
        'msg'=>'获取会话密钥失败'
    ));
}




